package com.course.app.transformer;

import com.course.app.api.data.TaskStoryDTO;
import com.course.domain.model.TaskStory;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by Justin on 2017/5/30.
 */
public class TaskStoryTransfromer {

    public static Map<Integer, TaskStoryDTO> toStoryMap(List<TaskStory> taskStoryList) {
        return taskStoryList.stream()
                .map(TaskStoryTransfromer::toStory)
                .collect(Collectors.toMap(TaskStoryDTO::getId, Function.identity()));
    }

    private static TaskStoryDTO toStory(TaskStory taskStory) {
        TaskStoryDTO storyDTO = new TaskStoryDTO();
        storyDTO.setId(taskStory.getId());
        storyDTO.setTitle(taskStory.getTitle());
        storyDTO.setDetail(taskStory.getDetail());
        storyDTO.setMediaLink(taskStory.getStoryLink());
        storyDTO.setAlbumLink(taskStory.getAlbumLink());
        storyDTO.setRepeatTimes(taskStory.getTimes());
        storyDTO.setWithBook(taskStory.getBookState().equals(TaskStory.BookState.WITH_BOOK));
        return storyDTO;
    }
}
